package com.github.postsanf.yinian.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.media.MediaMetadataRetriever;
import android.os.Build;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.TextAppearanceSpan;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.github.postsanf.yinian.R;
import com.github.postsanf.yinian.bean.YNLike;
import com.github.postsanf.yinian.constants.SelectedImg;
import com.github.postsanf.yinian.widget.CenterAlignImageSpan;

import java.io.File;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class UIHelper {
    public final static int MAX_IMG_COUNT = 10000;
    public final static int MIN_IMG_COUNT = 1;

    public static long getupstorge() {
        long totalSize = 0;
        for (int i = 0; i < SelectedImg.mSelectedImage.size(); i++) {
            String address = SelectedImg.mSelectedImage.get(i);
            if (!address.startsWith("http")) {
                File uploadImg = new File(address);
                long imgSize = uploadImg.length();
                totalSize += imgSize;
            }
        }
        return totalSize;
    }

    /**
     * dp转换px值
     */
    public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }

    /**
     * 将px值转换为dip或dp值，保证尺寸大小不变
     */
    public static int px2dip(Context context, float pxValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }

    public static int getHigh(Context context) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        int pwidth = wm.getDefaultDisplay().getWidth();
        int imgwidth = pwidth - DisplayUtils.dp2px(context, 110);
        return imgwidth / 3;
    }

    public static int getTimeCardHigh(Context context) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        int pwidth = wm.getDefaultDisplay().getWidth();
        int imgwidth = pwidth - DisplayUtils.dp2px(context, 35);
        return imgwidth * 496 / 380;
    }

    public static int getDaySignHight(Context context) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        int pwidth = wm.getDefaultDisplay().getWidth();
        int imgwidth = pwidth - DisplayUtils.dp2px(context, 90);
        return imgwidth * 902 / 610;
    }

    public static int getAlbumItemHighWidth(Context context) {
        return (getScreenWidth(context) - 3 * DisplayUtils.dp2px(context, 1)) / 4;
    }

    public static int getShopItemHigh(Context context) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        int pwidth = wm.getDefaultDisplay().getWidth();
        return pwidth * 1404 / 1562;
    }

    public static int getVoiceCardHigh(Context context) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        int pwidth = wm.getDefaultDisplay().getWidth();
        int imgwidth = pwidth - DisplayUtils.dp2px(context, 20);
        return imgwidth * 591 / 886;
    }

    public static int getVoiceCardPicWidth(Context context) {
        return getVoiceCardPicHigh(context) * 345 / 359;
    }

    public static int getVoiceCardPicHigh(Context context) {
        return getVoiceCardHigh(context) - DisplayUtils.dp2px(context, 70);
    }

    public static int getMyTimeCardHigh(Context context) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        int pwidth = wm.getDefaultDisplay().getWidth();
        int imgwidth = pwidth - DisplayUtils.dp2px(context, 90);
        return imgwidth * 768 / 550;
    }

    public static int getScreenWidth(Context context) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        return wm.getDefaultDisplay().getWidth();
    }

    public static int getScreenHeight(Context context) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        return wm.getDefaultDisplay().getHeight();
    }

    public static int getsingeHigh(Context context) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        int pwidth = wm.getDefaultDisplay().getWidth();
        int imgwidth = pwidth - DisplayUtils.dp2px(context, 110);
        return imgwidth * 422 / 586;
    }

    public static int getTmSingeHigh(Context context) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        int pwidth = wm.getDefaultDisplay().getWidth();
        int imgwidth = pwidth - DisplayUtils.dp2px(context, 85);
        return imgwidth;
    }

    public static int getVideoSingleHigh(Context context) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        int pwidth = wm.getDefaultDisplay().getWidth();
        int imgwidth = pwidth - DisplayUtils.dp2px(context, 25);
        return imgwidth;
    }

    public static int getPailideShowHigh(Context context) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        int pwidth = wm.getDefaultDisplay().getWidth();
        int imgwidth = pwidth - DisplayUtils.dp2px(context, 18);
        return imgwidth;
    }

    public static int getTmDoubleHigh(Context context) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        int pwidth = wm.getDefaultDisplay().getWidth();
        int imgwidth = pwidth - DisplayUtils.dp2px(context, 87);
        return imgwidth / 2;
    }

    public static int getTmThreeGdHigh(Context context) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        int pwidth = wm.getDefaultDisplay().getWidth();
        int imgwidth = pwidth - DisplayUtils.dp2px(context, 87);
        return imgwidth / 3;
    }

    public static int getTmForeGdHigh(Context context) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        int pwidth = wm.getDefaultDisplay().getWidth();
        int imgwidth = pwidth - DisplayUtils.dp2px(context, 100);
        return imgwidth / 4;
    }

    public static int getTmMoreGdHigh(Context context) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        int pwidth = wm.getDefaultDisplay().getWidth();
        int imgwidth = pwidth - DisplayUtils.dp2px(context, 87);
        return imgwidth * 2 / 3 + DisplayUtils.dp2px(context, 2);
    }

    public static void collapseStatusBar(Context context) {
        try {
            Object statusBarManager = context.getSystemService("statusbar");
            Method collapse;

            if (Build.VERSION.SDK_INT <= 16) {
                collapse = statusBarManager.getClass().getMethod("collapse");
            } else {
                collapse = statusBarManager.getClass().getMethod("collapsePanels");
            }
            collapse.invoke(statusBarManager);
        } catch (Exception localException) {
            localException.printStackTrace();
        }
    }

    public static String ToDBC(String str) {
        char[] c = str.toCharArray();
        for (int i = 0; i < c.length; i++) {
            if (c[i] == 12288) {
                c[i] = (char) 32;
                continue;
            }
            if (c[i] > 65280 && c[i] < 65375)
                c[i] = (char) (c[i] - 65248);
        }
        return new String(c);
    }

    public static String stringFilter(String str) {
        str = str.replaceAll("【", "[").replaceAll("】", "]")
                .replaceAll("！", "!").replaceAll("：", ":");// 替换中文标号
        String regEx = "[『』]"; // 清除掉特殊字符
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        return m.replaceAll("").trim();
    }

    public static List<List<String>> createList(List<String> targe, int size) {
        List<List<String>> listArr = new ArrayList<List<String>>();
        //获取被拆分的数组个数
        int arrSize = targe.size() % size == 0 ? targe.size() / size : targe.size() / size + 1;
        for (int i = 0; i < arrSize; i++) {
            List<String> sub = new ArrayList<String>();
            //把指定索引数据放入到list中
            for (int j = i * size; j <= size * (i + 1) - 1; j++) {
                if (j <= targe.size() - 1) {
                    sub.add(targe.get(j));
                }
            }
            listArr.add(sub);
        }
        return listArr;
    }

    public static Spannable getCommentContent(Context context, String nickname, String content) {
        String tx1 = nickname + UIHelper.stringFilter(UIHelper.ToDBC(":" + " " + content));
        Spannable WordtoSpan = new SpannableString(tx1);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style4), 0, nickname.length() + 1,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style5), nickname.
                        length() + 1, tx1.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return WordtoSpan;
    }

    public static Spanned getTextHtml(final Context context, String text) {
        Html.ImageGetter imageGetter = new Html.ImageGetter() {
            public Drawable getDrawable(String source) {
                Drawable drawable = null;
                int rId = Integer.parseInt(source);
                drawable = context.getResources().getDrawable(rId);
                drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
                return drawable;
            }
        };
        return Html.fromHtml(text, imageGetter, null);
    }

    public static Spanned getTextHtmlMic1(final Context context, String ePeopleName, String Eplace) {
        String sText1 = "和    ";
        String sText2 = "    在    ";
        String sText4 = "    一起留下了一段声音";
//        String sText1 = "<small><font color='#666666'>" + "和      " + "</font></small>" +
//                "<font color='#333333'>" + ePeopleName + "</font>" +
//                "<small><font color='#666666'>" + "  在     " + "</font></small>" +
//                "<img src=\"" + R.drawable.timeline_item_location2 + "\" />"
//                + "<font color='#2d47a8'>" + Eplace + "</font>"
//                + "<small><font color='#666666'>" + " " + sText4 + "</font></small>";
//        return getTextHtml(context, sText1);
        String tx = sText1 + ePeopleName + sText2 + Eplace + sText4;
        Spannable WordtoSpan = new SpannableString(tx);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style6), 0, sText1.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style5), sText1.length(), sText1.length() + ePeopleName.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style6), sText1.length() + ePeopleName.length(), sText1.length() + ePeopleName.length() + sText2.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style4), sText1.length() + ePeopleName.length() + sText2.length(), sText1.length() + ePeopleName.length() + sText2.length() + Eplace.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style6), sText1.length() + ePeopleName.length() + sText2.length() + Eplace.length(), tx.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        Drawable drawable = context.getResources().getDrawable(R.drawable.timeline_item_location2);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        WordtoSpan.setSpan(new CenterAlignImageSpan(drawable), sText1.length() + ePeopleName.length() - 1 + sText2.length(), sText1.length() + ePeopleName.length() + sText2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return WordtoSpan;
    }


    public static Spanned getTextHtmlMic2(final Context context, String ePeopleName) {
        String sText1 = "和    ";
        String sText3 = "    一起留下了一段声音";
//        String sText1 = "<small><font color='#666666'>" + "和    " + "</font></small>" +
//                "<font color='#333333'>" + ePeopleName
//                + "<small><font color='#666666'>" + " " + sText3 + "</font></small>";
//        return getTextHtml(context, sText1);
        String tx = sText1 + ePeopleName + sText3;
        Spannable WordtoSpan = new SpannableString(tx);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style6), 0, sText1.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style5), sText1.length(), sText1.length() + ePeopleName.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style6), sText1.length() + ePeopleName.length(), tx.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return WordtoSpan;
    }

    public static Spanned getTextHtmlMic3(final Context context, String Eplace) {
        String sText2 = "在    ";
        String sText3 = "    留下了一段声音";
//        String sText1 = "<small><font color='#666666'>" + "在    " + "</font></small>" +
//                "<img src=\"" + R.drawable.timeline_item_location2 + "\" />"
//                + "<font color='#2d47a8'>" + Eplace + "</font>"
//                + "<small><font color='#666666'>" + " " + sText3 + "</font></small>";
//        return getTextHtml(context, sText1);
        String tx = sText2 + Eplace + sText3;
        Spannable WordtoSpan = new SpannableString(tx);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style6), 0, sText2.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style4), sText2.length(), sText2.length() + Eplace.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style6), sText2.length() + Eplace.length(), tx.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        Drawable drawable = context.getResources().getDrawable(R.drawable.timeline_item_location2);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        WordtoSpan.setSpan(new CenterAlignImageSpan(drawable), sText2.length() - 1, sText2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return WordtoSpan;
    }

    public static Spanned getTextHtmlfuMic1(final Context context, String ePeopleName, String Eplace) {
//        String sText1 = "<small><font color='#666666'>" + "和    " + "</font></small>" +
//                "<font color='#333333'>" + ePeopleName + "</font>" +
//                "<small><font color='#666666'>" + "  在    " + "</font></small>" +
//                "<img src=\"" + R.drawable.timeline_item_location2 + "\" />"
//                + "<font color='#2d47a8'>" + Eplace + "</font>";
//        return getTextHtml(context, sText1);
        String sText1 = "和    ";
        String sText2 = "    在    ";
        String tx = sText1 + ePeopleName + sText2 + Eplace;
        Spannable WordtoSpan = new SpannableString(tx);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style6), 0, sText1.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style5), sText1.length(), sText1.length() + ePeopleName.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style6), sText1.length() + ePeopleName.length(), sText1.length() + ePeopleName.length() + sText2.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style4), sText1.length() + ePeopleName.length() + sText2.length(), tx.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        Drawable drawable = context.getResources().getDrawable(R.drawable.timeline_item_location2);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        WordtoSpan.setSpan(new CenterAlignImageSpan(drawable), sText1.length() + ePeopleName.length() + sText2.length() - 1, sText1.length() + ePeopleName.length() + sText2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return WordtoSpan;
    }

    public static Spanned getTextHtmlfuMic2(final Context context, String ePeopleName) {
        String sText1 = "和    ";
        String sText3 = "    一起留下了一段声音";
//        String sText1 = "<small><font color='#666666'>" + "和    " + "</font></small>" +
//                "<font color='#333333'>" + ePeopleName
//                + "<small><font color='#666666'>" + " " + sText3 + "</font><small>";
//        return getTextHtml(context, sText1);
        String tx = sText1 + ePeopleName + sText3;
        Spannable WordtoSpan = new SpannableString(tx);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style6), 0, sText1.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style5), sText1.length(), sText1.length() + ePeopleName.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style6), sText1.length() + ePeopleName.length(), tx.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return WordtoSpan;
    }

    public static Spanned getTextHtmlfuMic3(final Context context, String ePeopleName) {
//        String sText1 = "<small><font color='#666666'>" + "和    " + "</font></small>" +
//                "<font color='#333333'>" + ePeopleName;
//        return getTextHtml(context, sText1);
        String sText1 = "和    ";
        String tx = sText1 + ePeopleName;
        Spannable WordtoSpan = new SpannableString(tx);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style6), 0, sText1.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style5), sText1.length(), tx.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return WordtoSpan;
    }

    public static Spanned getTextHtmlLocation1(final Context context, String ePeopleName, String Eplace) {
        String sText1 = "和    ";
        String sText2 = "    在    ";
//        String lText1 = "<small><font color='#666666'>" + "和    " + "</font></small>" +
//                "<font color='#333333'>" + ePeopleName + "</font>" +
//                "<small><font color='#666666'>" + "  在    " + "</font></small>" +
//                "<img src=\"" + R.drawable.timeline_item_location2 + "\" />"
//                + "<font color='#2d47a8'>" + Eplace + "</font>";
//        return getTextHtml(context, lText1);
        String tx = sText1 + ePeopleName + sText2 + Eplace;
        Spannable WordtoSpan = new SpannableString(tx);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style6), 0, sText1.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style5), sText1.length(), sText1.length() + ePeopleName.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style6), sText1.length() + ePeopleName.length(), sText1.length() + ePeopleName.length() + sText2.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style4), sText1.length() + ePeopleName.length() + sText2.length(), tx.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        Drawable drawable = context.getResources().getDrawable(R.drawable.timeline_item_location2);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        WordtoSpan.setSpan(new CenterAlignImageSpan(drawable), sText1.length() + ePeopleName.length() + sText2.length() - 1, sText1.length() + ePeopleName.length() + sText2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return WordtoSpan;
    }

    public static Spanned getTextHtmlLocation2(final Context context, String Eplace) {
//        String lText1 = "<small><font color='#666666'>" + "在    " + "</font></small>" +
//                "<img src=\"" + R.drawable.timeline_item_location2 + "\" />"
//                + "<font color='#2d47a8'>" + Eplace + "</font>";
//        return getTextHtml(context, lText1);
        String sText2 = "在    ";
        String tx = sText2 + Eplace;
        Spannable WordtoSpan = new SpannableString(tx);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style6), 0, sText2.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.item_comment_text_style4), sText2.length(), tx.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        Drawable drawable = context.getResources().getDrawable(R.drawable.timeline_item_location2);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        WordtoSpan.setSpan(new CenterAlignImageSpan(drawable), sText2.length() - 1, sText2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return WordtoSpan;
    }


    public static boolean juideIsContionMe(List<YNLike> likeList, int userid) {
        for (int i = 0; i < likeList.size(); i++) {
            if (likeList.get(i).getLikeUserID() == userid) {
                return true;
            }
        }
        return false;
    }


    public static Spanned getTextNumInvite(final Context context, String str) {
        Spannable WordtoSpan = new SpannableString(str);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.kuorong_text_style1), 0, str.length() - 4,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.kuorong_text_style2), str.length() - 4, str.length() - 3,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        WordtoSpan.setSpan(new TextAppearanceSpan(context, R.style.kuorong_text_style1), str.length() - 3, str.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return WordtoSpan;
    }

    public static void setFace(int LikeStatus, ImageView avatartype) {
        switch (LikeStatus) {
            case 2:
                avatartype.setImageResource(R.drawable.timeline_face1);
                break;
            case 4:
                avatartype.setImageResource(R.drawable.timeline_face2);
                break;
            case 5:
                avatartype.setImageResource(R.drawable.timeline_face3);
                break;
            case 3:
                avatartype.setImageResource(R.drawable.timeline_face4);
                break;
            case 0:
                avatartype.setImageResource(R.drawable.timeline_face5);
                break;
        }
    }

    public static void setTextFace(int LikeStatus, TextView avatartype) {
        switch (LikeStatus) {
            case 2:
                avatartype.setBackgroundResource(R.drawable.timeline_face1);
                break;
            case 4:
                avatartype.setBackgroundResource(R.drawable.timeline_face2);
                break;
            case 5:
                avatartype.setBackgroundResource(R.drawable.timeline_face3);
                break;
            case 3:
                avatartype.setBackgroundResource(R.drawable.timeline_face4);
                break;
            case 0:
                avatartype.setBackgroundResource(R.drawable.timeline_face5);
                break;
        }
    }

    public static int getCameraPublishImgHigh(Context context) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        int pwidth = wm.getDefaultDisplay().getWidth();
        int imgwidth = pwidth - DisplayUtils.dp2px(context, 28);
        return imgwidth;
    }

    public static Bitmap getVideoThumbnail(String videoPath) {
        Bitmap bitmap = null;
        if (StringUtils.isEmpty(videoPath))
            return null;
        try {
            MediaMetadataRetriever media = new MediaMetadataRetriever();
            media.setDataSource(videoPath);
            bitmap = media.getFrameAtTime();
        } catch (Exception e) {
            return null;
        }
        return bitmap;
    }

}